﻿using HumanResourcesModule.Interfaces;
using HumanResourcesModule.View;
using HumanResourcesModule.ViewModel;
using Infrastructure.Events;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;

namespace HumanResourcesModule
{
    public class HRModule : IModule
    {

        #region init
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;
        private readonly IEventAggregator _eventAggregator;

        public HRModule(IRegionManager regionManager, IUnityContainer container,
            IEventAggregator eventAggregator)
        {
            _regionManager = regionManager;
            _container = container;
            _eventAggregator = eventAggregator;
        }
        #endregion

        #region IModule Members

        public void Initialize()
        {
            // zarejestruje nowe typy w kontenerze		
            _container.RegisterType<IEmployeeView, EmployeeView>();
            _container.RegisterType<IEmployeeViewModel, EmployeeViewModel>();
            _container.RegisterType<IEmployeeEditView, EmployeeEditView>();
            _container.RegisterType<IEmployeeEditViewModel, EmployeeEditViewModel>();

            // Powiadom menadzer regionow, w ktorym regionie wyswietli sie dany widok
            _regionManager.RegisterViewWithRegion("MainView", () => new EmployeeView());

            // Powiadom wszystkich nasluchujacych o zakonczeniu inicjalizacji modulu
            _eventAggregator.GetEvent<ViewInitializedEvent>().Publish("HumanResourcesModule");
        }
        #endregion
    }
}
